package com.shujia.base;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
    使用java传统的做法统计每个班级人数

    文科六班-94
    文科二班-77
    文科三班-85
    理科五班-64
    文科四班-76
    理科一班-70
    文科五班-73
    理科六班-84
    理科二班-67
    文科一班-63
    理科三班-63
    理科四班-82
 */
public class ClazzNumberTest {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("D:\\projects\\IdeaProjects\\bigdata32\\hadoop\\data\\studentTest.txt"));
        HashMap<String, Long> map = new HashMap<>();
        String line = null;
        while ((line = br.readLine()) != null) {
            //1500100882,厍振强,21,男,文科五班
            String clazz = line.split(",")[4];
            if (map.containsKey(clazz)) {
                map.put(clazz, map.get(clazz) + 1);
            } else {
                map.put(clazz, 1L);
            }
        }
        Set<Map.Entry<String, Long>> entries = map.entrySet();
        for (Map.Entry<String, Long> entry : entries) {

            String clazz = entry.getKey();
            Long number = entry.getValue();

            System.out.println(clazz + "-" + number);
        }
        br.close();
    }
}
